<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8" />
<title>猎头分润</title>
<link href="${ctx}/static/bootstrap/css/bootstrap.min.css"
	rel="stylesheet" type="text/css" />
<link href="${ctx}/static/dist/css/font-awesome.min.css"
	rel="stylesheet" type="text/css" />
<link href="${ctx}/static/plugins/datatables/css/matrix-style.css"
	rel="stylesheet" type="text/css" />
<link href="${ctx}/static/dist/css/AdminLTE.css" rel="stylesheet"
	type="text/css" />
<link href="${ctx}/static/plugins/layer/skin/default/layer.css"
	rel="stylesheet" type="text/css" />
<link
	href="${ctx}/static/plugins/datatables/css/dataTables.bootstrap.css"
	rel="stylesheet" type="text/css" />
<style>
button.searching {
	background-color: #666
}
</style>
</head>
<body>
	<div class="widget-box">
		<div class="widget-title">
			<h5>请输入查询条件</h5>
		</div>
		<div class="widget-content nopadding">
			<table style="line-height:45px;font-size:12px;">
				<tr>
					<td>&nbsp;&nbsp;&nbsp;订单号：</td>
					<td><input type="text" class="form-control" name="orderNo"
						id="orderNo" style="width:200px;" placeholder="请输入你的信息"></td>
					<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn btn-success"
						href="javascript:void(0);" onclick="query();">查 询</a>
					</td>
					<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a class="btn btn-primary"
						href="/api/hunter/exporthunterprofit"
						id="exportExcel">导出数据</a>
					</td>
				</tr>
			</table>
			<div id="area_div" style="margin-left: 10px"></div>
		</div>
	</div>
	<div class="row">
		<div class="col-xs-12">
			<div class="box">
				<div class="box-header">
					<h3 class="box-title">猎头分润表</h3>
				</div>
				<!-- 列表 -->
				<div class="box-body table-responsive">
					<table id="dataTables" class="table table-bordered table-hover">
					</table>
				</div>
			</div>
		</div>
	</div>
	<!-- 审核 -->
	<div class="addr_form" id="initAuditWin" style="display:none;">
		<form id="profitForm">
			<table>
				<tbody>
					<tr>
						<td>
							<div class="form-group">
								<div class="col-sm-4" align="center">
									<textarea id="reason" name="reason"
										style="width: 200px;height: 90px;"></textarea>
								</div>
							</div>
						</td>
					</tr>
					<tr>
						<td>
							<div class="form-group">
								<div class="edit_btn" align="center">
									<button type="button" class="btn btn-primary"
										onclick="audit(1);" id="pass">通过</button>
									<button type="button" class="btn btn-danger" id="unpass"
										onclick="audit(2)">不通过</button>
									<button type="button" class="btn btn-danger" id="cancel"
										onclick="closeLayer()">取消</button>
								</div>
							</div>
						</td>
					</tr>
					<input type="hidden" id="tableType" name="tableType" value="2" />
					<!-- 标志是什么分润表1管理费分润,2猎头分润 -->
					<input type="hidden" id="profitId" name="profitId">
					<input type="hidden" id="status" name="status">
				</tbody>
			</table>
		</form>
	</div>
	<script src="${ctx}/static/plugins/jQuery/jQuery-2.1.4.min.js"></script>
	<script src="${ctx}/static/bootstrap/js/bootstrap.min.js"></script>
	<!-- datatable -->
	<script src="${ctx}/static/plugins/datatables/jquery.dataTables.js"
		type="text/javascript"></script>
	<script src="${ctx}/static/plugins/datatables/dataTables.bootstrap.js"
		type="text/javascript"></script>
	<script src="${ctx}/static/plugins/layer/layer.js"
		type="text/javascript"></script>
	<script src="${ctx}/static/js/common/area.js" type="text/javascript"></script>
	<script src="${ctx}/static/js/common/common.js" type="text/javascript"></script>
	<script>
		var tb;
		$(function() {
			//列表初始化
			tb = $('#dataTables')
					.dataTable(
							{
								"bServerSide" : true,
								"sPaginationType" : "full_numbers",
								"bJQueryUI" : true,
								"sDom" : '<"">t<"F"ip>',
								"sAjaxSource" : "/api/hunter/listhunterprofit", //ajax调用接口
								"aoColumnDefs" : [ {
									sDefaultContent : '',
									aTargets : [ '_all' ]
								} ],
								"aoColumns" : [
										{
											"sTitle" : "序号",
											"mData" : "id",
											"class" : "sClass"
										},
										{
											"sTitle" : "订单号",
											"mData" : "orderNo",
											"class" : "sClass"
										},
										{
											"sTitle" : "订单金额",
											"mData" : "orderMoney",
											"class" : "sClass"
										},
										{
											"sTitle" : "猎头分润",
											"mData" : "hunterProfit",
											"class" : "sClass"
										},
										{
											"sTitle" : "普惠分润",
											"mData" : "phProfit",
											"class" : "sClass"
										},
										{
											"sTitle" : "管理费",
											"mData" : "chargeProfit",
											"class" : "sClass"
										},
										{
											"sTitle" : "普惠管理费",
											"mData" : "phChargeProft",
											"class" : "sClass"
										},
										{
											"sTitle" : "易商通管理费",
											"mData" : "ystCHargeProfit",
											"class" : "sClass"
										},
										{
											"sTitle" : "市代名称",
											"mData" : "shiName",
											"class" : "sClass"
										},
										{
											"sTitle" : "市级代理管理费分润",
											"mData" : "shiProfit",
											"class" : "sClass"
										},
										{
											"sTitle" : "县代名称",
											"mData" : "xianName",
											"class" : "sClass"
										},
										{
											"sTitle" : "县级代理管理费分润",
											"mData" : "xianProfit",
											"class" : "sClass"
										},
										{
											"sTitle" : "市代推广师名称",
											"mData" : "shiRName",
											"class" : "sClass"
										},
										{
											"sTitle" : "推广师推市代分润",
											"mData" : "shiRProfit",
											"class" : "sClass"
										},
										{
											"sTitle" : "县代推广师名称",
											"mData" : "xianRName",
											"class" : "sClass"
										},
										{
											"sTitle" : "推广师推县代分润",
											"mData" : "xianRProfit",
											"class" : "sClass"
										},
										{
											"sTitle" : "管理费支出合计",
											"mData" : "chargeProfitTotal",
											"class" : "sClass"
										},
										{
											"sTitle" : "管理费剩余",
											"mData" : "chargeProfitRemain",
											"class" : "sClass"
										},

										{
											"sTitle" : "供应链利润",
											"mData" : "chainProfit",
											"class" : "sClass"
										},
										{
											"sTitle" : "普惠供应链收入",
											"mData" : "phChainProfit",
											"class" : "sClass"
										},
										{
											"sTitle" : "易商通供应链收入",
											"mData" : "ystChainProfit",
											"class" : "sClass"
										},
										{
											"sTitle" : "市级代理供应链分润",
											"mData" : "shiChainProfit",
											"class" : "sClass"
										},
										{
											"sTitle" : "县级代理供应链分润",
											"mData" : "xianChainProfit",
											"class" : "sClass"
										},
										{
											"sTitle" : "供应链支出合计",
											"mData" : "chainProfitTotal",
											"class" : "sClass"
										},
										{
											"sTitle" : "供应链剩余",
											"mData" : "chainProfitRemain",
											"class" : "sClass"
										},
										{
											"sTitle" : "审核人",
											"mData" : "auditor",
											"class" : "sClass"
										},
										{
											"sTitle" : "审核时间",
											"mData" : "auditDate",
											"class" : "sClass"
										},
										{
											"sTitle" : "审核状态",
											"mData" : "auditStatus",
											"class" : "sClass",
											"mRender" : function(data, type,
													full) {
												var text;
												var status = full.auditStatus;
												switch (status) {
												//状态(0待审核，1审核通过，2审核不通过)
												case 0:
													text = "待审核";
													break;
												case 1:
													text = "审核通过";
													break;
												case 2:
													text = "审核不通过";
													break;
												default:
													text = "未知状态";
													break;
												}
												return text;
											}
										},
										{
											"sTitle" : "审核原因",
											"mData" : "reason",
											"class" : "sClass"
										},
										{
											"sTitle" : "分润时间",
											"mData" : "profitTime",
											"class" : "sClass"
										},
										{
											"sTitle" : "创建时间",
											"mData" : "createTime",
											"class" : "sClass",
											"bVisible" : false
										},
										{
											"sTitle" : "操作",
											"mData" : "id",
											"mRender" : function(data, type,
													full) {
												var text = '<div class="btn-group" style="text-align:left;"><button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown">操作 <span class="caret"></span></button>';
												text = text
														+ '<ul class="dropdown-menu" role="menu">';
												text += '<li class="divider"></li>';
												text += '<li><a href="javascript:void(0)" onclick="initAudit(\''
														+ full.id
														+ '\',\''
														+ full.auditStatus
														+ '\');">审核</a></li>';
												text += '<li class="divider"></li>';
												return text;
											}
										} ],
								"oLanguage" : {
									"sProcessing" : "数据加载中······",
									"sLengthMenu" : "显示 _MENU_ 条记录",
									"sZeroRecords" : "没有您要搜索的内容！",
									"sEmptyTable" : "列表中无数据存在！",
									"sInfo" : "当前显示 _START_ 到 _END_ 条数据，共 _TOTAL_ 条数据",
									"sInfoEmpty" : "显示 0 到 0 条记录",
									"sInfoFiltered" : "数据列表中共  _MAX_ 条记录",
									"oPaginate" : {
										"sFirst" : "首页",
										"sPrevious" : "上一页",
										"sNext" : "下一页",
										"sLast" : "末页"
									}
								},
								"fnServerData" : function(sSource, aoData,
										fnCallback, oSettings) {
									oSettings.jqXHR = $
											.ajax({
												"dataType" : 'json',
												"type" : "GET",
												"async" : 'false',
												"url" : sSource,
												"data" : {
													'pageNum' : (aoData[3].value / aoData[4].value) + 1,
													'pageSize' : aoData[4].value,
													'orderNo' : $("#orderNo")
															.val(),
												},
												"success" : fnCallback
											});
								}
							});
		});
		//条件查询重新加载数据
		function query() {
			tb.fnDraw();
		}
		function closeLayer() {
			layer.closeAll();
		}

		function initAudit(id, status) {
			$("#profitId").val(id);
			$("#status").val(status);
			layer.open({
				title : "审核原因",
				type : 1,
				closeBtn : true,
				resize : false,
				area : [ '230px', '200px' ], // 宽高
				content : $("#initAuditWin")
			});
		}

		function audit(operation) {
			if (operation == 1) {
				$("#status").val(operation);
			} else if (operation == 2) {
				$("#status").val(operation);
			} else {
				$("#status").val("");
			}
			var jsonData = $("#profitForm").serializeJson();
			$.ajax({
				url : '/api/hunter/auditoper',
				type : 'post',
				data : jsonData,
				dataType : 'json',
				success : function(data) {
					if (data.code == 200) {
						$("#dataTables").DataTable().fnDraw();
						layer.alert(data.message, {
							yes : function() {
								closeLayer();
							}
						});
					} else {
						layer.alert("系统繁忙,请稍后再试!");
					}
				},
				error : function(error) {
					if (data.code == 500) {
						layer.alert(data.message);
					}
				}
			});
		}
		
	</script>
</body>
</html>
